package com.wen.system.oauth;

import com.wen.common.exception.CustomException;
import me.zhyd.oauth.config.AuthConfig;
import me.zhyd.oauth.request.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.Map;

/**
 * <p>
 *
 * @author liwen <devinlive@163.com>
 * @version 1.0
 * @since 2023-09-03 21:04
 */
@Component
public class OAuthSimpleFactory {

    private String config;
    @Autowired
    private OAuthProperties oAuthProperties;

    private Map<String,String> map;



    public OAuthSimpleFactory() {
    }

    public OAuthSimpleFactory(String authConfigKey) {
        this.config = authConfigKey;
        String s = map.get(authConfigKey);


    }

    /**
     * 目前根据不同的key类型，获取对应properties的值只想到这种办法，一个类对应一个properties
     * @param type
     * @return
     */
    public AuthRequest getAuthRequest(String type) {
        switch (type) {
            case "Gitee":
                return buildAuthGitee();
            case "Alipay":
                return buildAuthAlipay();
            case "QQ":
                return buildAuthQq();
            case "Wx":
                return buildAuthWeChat();
            default:
                throw new CustomException("暂不支持当前登录类型！");
        }
    }

    private AuthDefaultRequest buildAuthGitee(){
        OAuthProperties.GiteeProperties giteeProperties = oAuthProperties.getGitee();
        return new AuthGiteeRequest(AuthConfig.builder()
                .clientId(giteeProperties.getClientId())
                .clientSecret(giteeProperties.getClientSecret())
                .redirectUri(giteeProperties.getRedirectURI())
                .ignoreCheckState(true)
                .build());
    }
    private AuthDefaultRequest buildAuthAlipay(){
        OAuthProperties.AlipayProperties alipayProperties = oAuthProperties.getAlipay();
        return new AuthAlipayRequest(AuthConfig.builder()
                .clientId(alipayProperties.getClientId())
                .clientSecret(alipayProperties.getClientSecret())
                .redirectUri(alipayProperties.getRedirectURI())
                .ignoreCheckState(true)
                .build());
    }
    private AuthDefaultRequest buildAuthQq(){
        OAuthProperties.AlipayProperties alipayProperties = oAuthProperties.getAlipay();
        return new AuthQqRequest(AuthConfig.builder()
                .clientId(alipayProperties.getClientId())
                .clientSecret(alipayProperties.getClientSecret())
                .redirectUri(alipayProperties.getRedirectURI())
                .ignoreCheckState(true)
                .build());
    }
    private AuthDefaultRequest buildAuthWeChat(){
        OAuthProperties.AlipayProperties alipayProperties = oAuthProperties.getAlipay();
        return new AuthWeChatEnterpriseQrcodeRequest(AuthConfig.builder()
                .clientId(alipayProperties.getClientId())
                .clientSecret(alipayProperties.getClientSecret())
                .redirectUri(alipayProperties.getRedirectURI())
                .ignoreCheckState(true)
                .build());
    }

}
